using System;
using System.Collections.Generic;
using StructureMap;
using Nvigorate.Extensions;
using StructureMap.Attributes;

namespace Nvigorate.Repository.Test
{
    public abstract class DomainNotification : IDomainNotification
    {
        protected DateTime _occurred = DateTime.Now;

        public virtual string Message { get; set; }
        public virtual DateTime Occurred { get { return _occurred; } }
        
        public static void Send(IDomainNotification notification)
        {
            ObjectFactory.GetInstance<INotificationBroker>().Dispatch(notification);
        }

        static DomainNotification()
        {
            ObjectFactory.Configure(c => 
                                    {
                                        c.Scan(s =>
                                                   {
                                                       s.TheCallingAssembly();
                                                       s.AddAllTypesOf<ICommandResult>();
                                                       s.WithDefaultConventions();
                                                   });
                                        c.ForRequestedType<INotificationBroker>().AddConcreteType<NotificationBroker>().
                                            CacheBy(InstanceScope.Singleton);
                                        c.ForRequestedType<NotificationScope>().TheDefaultIsConcreteType<NotificationScope>();
                                    });
            
        }
    }
}